import groovy.sql.Sql

def ctx = new javax.naming.InitialContext()
def conn = ctx.lookup("jdbc/vwru")
def sql = new groovy.sql.Sql(conn)

def sqlString = """

select vvin, vmobile, decode(vtel, '-', '', vtel) tel, to_char(dcrtdate, 'yyyy-mm-dd') d 
from 
(select min(dcrtdate) dd from (
select vvin || '_' || vmobile || '_' || vtel v, dcrtdate from MS_CAMP_DSGVIN_TEL
where to_char(dcrtdate, 'yyyymmdd') = '20130405')
group by v) a,
MS_CAMP_DSGVIN_TEL b
where a.dd = b.dcrtdate

"""
def null2string = { src ->
	if(src == null)
		src = ""
	return src.toString().trim()
}
def columnNames
def rows = sql.rows(sqlString) { meta -> 
        columnNames = (1..meta.columnCount).collect { 
            meta.getColumnName(it) 
        } 
    
}

println '<pre>'
columnNames.each{ it ->
        //print it + "\t"
        print it + '&#9;'
}
print "<br/>"
rows.each{ row ->
   columnNames.each{ col ->
   	print null2string(row[col]) + '&#9;'
   }
   print "<br/>"
}
println '</pre>'
return null